<?php
namespace voxfa\net;

use voxfa\net\core\InetAddressSupport;

class InetAddress {
	
	const SC_GLOBAL = "global";
	const SC_LINK = "link";
	const SC_SITE = "site";
	const SC_HOST = "host";
	
	protected $name;
	protected $address=array();
	protected $attrs=array();
	
	protected $support;
	
	public function __construct(){
		$this->support = new InetAddressSupport();
	}

	public function getName() {
		return $this->name;
	}

	/**
	 * @param $name the $name to set
	 */
	public function setName($name) {
		$this->name = $name;
	}

	public function getAddress() {
		return $this->address;
	}

	/**
	 * @param $address the $address to set
	 */
	public function setAddress($address) {
		$this->address = $address;
	}
	
	public function getAttribute($key){
		if (array_key_exists($key,$this->attrs))
			return $this->attrs[$key];
		return null;
	}
	
	public function setAttribute($key,$value){
		$this->attrs[$key]=$value;	
	}
	
	public function getAttributes(){
		return $this->attrs;
	}
	
	public function setAttributes($attrs){
		$this->attrs = $attrs;
	}
	
	public function save(){
		return $this->support->removeByName($this->name);
	}
	
	public function remove(){
		return $this->support->removeByAddress($this->address);
	}
	
	/**
	 * @return InetAddress
	 * @param unknown_type $address
	 */
	public static function getByAddress($address){
		return $this->support->getByAddress($address);
	}
	
	public static function getByName($interfaceName){
		return $this->support->getByAddress($interfaceName);
	}
	
	public static function existByAddress($address){
		return $this->support->existByAddress($address);
	}
}